CFLAGS = -Wall -Wno-unused-variable -fpic -Wno-unused-but-set-variable -coverage -lm
PROGS = playdom player unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard

default: all

all: playdom tests

rngs.o: rngs.h rngs.c
	@gcc -c rngs.c -g $(CFLAGS)

dominion.o: dominion.h dominion_helpers.h dominion.c rngs.o
	@echo "Compiling Dominion Game.."
	@gcc -c dominion.c -g $(CFLAGS)

playdom: dominion.o playdom.c
	@gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)
   
player: player.c interface.o
	@gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS)
   
tests: rngs.o dominion.o unittest1.c unittest2.c unittest3.c unittest4.c randomtestadventurer.c randomtestcard.c
	@echo "Compiling tests..."
	@gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)
	@gcc -o unittest2 -g unittest2.c dominion.o rngs.o $(CFLAGS)
	@gcc -o unittest3 -g unittest3.c dominion.o rngs.o $(CFLAGS)
	@gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)
	@gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o $(CFLAGS)
	@gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o $(CFLAGS)
	@gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)
	@gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o $(CFLAGS)
	@gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
	@gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)

   
runtests: tests
	@echo "running unit test #1..."
	@echo -e "Starting Unit Test 1.........\n*************************************************************\n" >> unittestresults.out
	@./unittest1 101 10000 >> unittestresults.out

	@echo "running unit test #2..."
	@echo -e "\n\nStarting Unit Test 2.........\n**************************************************************\n" >> unittestresults.out
	@./unittest2 101 10000 >> unittestresults.out

	@echo "running unit test #3..."
	@echo -e "\n\nStarting Unit Test 3.........\n**************************************************************\n" >> unittestresults.out
	@./unittest3 101 10000 >> unittestresults.out

	@echo "running unit test #4..."
	@echo -e "\n\nStarting Unit Test 4.........\n**************************************************************\n" >> unittestresults.out
	@./unittest4 101 100 >> unittestresults.out

	@echo "running card test #1..."
	@echo -e "\n\nStarting Card Test 1.........\n**************************************************************\n" >> unittestresults.out
	@./cardtest1 101 100 >> unittestresults.out

	@echo "running card test #2..."
	@echo -e "\n\nStarting Card Test 2.........\n**************************************************************\n" >> unittestresults.out
	@./cardtest2 101 1000 >> unittestresults.out

	@echo "running card test #3..."
	@echo -e "\n\nStarting Card Test 3.........\n**************************************************************\n" >> unittestresults.out
	@./cardtest3 101 1000 >> unittestresults.out

	@echo "running card test #4..."
	@echo -e "\n\nStarting Card Test 4.........\n**************************************************************\n" >> unittestresults.out
	@./cardtest4 101 1000 >> unittestresults.out

	@echo -e "\n\nCoverage Statistics.........\n**************************************************************\n" >> unittestresults.out
	@echo "outputting coverage data to file..."
	@gcov -b -c -f dominion.c >> unittestresults.out

	@echo -e "\n\nDominion.c Coverage.........\n**************************************************************\n" >> unittestresults.out
	@cat dominion.c.gcov >> unittestresults.out

runrandomtests:
	@echo "running random testing on Adventurer Card..."
	@./randomtestadventurer 101 10000 > randomtestadventurer.out

	@echo "running random testing on Steward Card..."
	@./randomtestcard 101 10000 > randomtestcard.out
	
clean:
	@echo "Cleaning up..."
	@rm -f *.o $(PROGS) unittestresults.out *.gcov *.gcda *.gcno *.so

#########################################################################

testDrawCard: testDrawCard.c dominion.o rngs.o
	@gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	@gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testDrawCard.c dominion.o rngs.o
	@gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	@gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	@gcc -c interface.c -g  $(CFLAGS)

runtests_old: testDrawCard 
	@./testDrawCard &> unittestresult.out
	@gcov dominion.c >> unittestresult.out
	@cat dominion.c.gcov >> unittestresult.out






